package huhx.linux.com.kotlinlearn.http

import android.content.Context
import android.widget.Toast

import huhx.linux.com.kotlinlearn.common.ResponseBean
import huhx.linux.com.kotlinlearn.constants.TransConstants
import io.reactivex.functions.Consumer

/**
 * Created by huhx on 2018-03-17 下午 8:12.
 */

abstract class SuccessConsumer<T> internal constructor(private val context: Context) : Consumer<ResponseBean<T>> {

    @Throws(Exception::class)
    override fun accept(responseBean: ResponseBean<T>) {
        val returnCode = responseBean.returnCode
        if (returnCode == TransConstants.TRAN_SUCCESS) {
            accpet(responseBean.response)
        } else if (returnCode == TransConstants.NOT_LOGIN) {
            Toast.makeText(context, responseBean.returnMsg, Toast.LENGTH_SHORT).show()
        } else if (returnCode == TransConstants.UNKNOW_ERROR) {
            Toast.makeText(context, responseBean.returnMsg, Toast.LENGTH_SHORT).show()
        } else {

        }
    }

    abstract fun accpet(response: T)
}
